//
//  TJStatus.m
//  TJSinaWeiBo_OC
//
//  Created by 唐后能 on 16/4/27.
//  Copyright © 2016年 itheima. All rights reserved.
//

#import "TJStatus.h"

@implementation TJStatus

// 字典转模型.
-(instancetype)initWithDict:(NSDictionary*)dict {
    
    if (self=[super init]) {
        [self setValuesForKeysWithDictionary:dict];
    }
    return self;
}

-(void)setValue:(id)value forUndefinedKey:(NSString *)key{}

+(instancetype)statusWithDict:(NSDictionary*)dict {
    
    return [[self alloc] initWithDict:dict];
}

// 拦截setValue:forKey:给user属性和retweeted_status属性再次转模型.
- (void)setValue:(id)value forKey:(NSString *)key {

    // 如果是用户模型.
    if ([key isEqualToString:@"user"]) {
        self.user = [TJUser userWithDict:value];
        return;
    }
    // 如果是被转发的微博模型.
    if ([key isEqualToString:@"retweeted_status"]) {
        self.retweeted_status = [TJStatus statusWithDict:value];
        return;
    }
    
    [super setValue:value forKey:key];
}

// 给外界直接使用的图片数组赋值.
-(void)setPic_urls:(NSArray<NSDictionary *> *)pic_urls {

    pic_urls = pic_urls;
    for (NSDictionary *pic_url in pic_urls) {
        NSURL *URL1 = [NSURL URLWithString:pic_url[@"thumbnail_pic"]];
        [self.thumbnail_pics addObject:URL1];
        NSURL *URL2 = [NSURL URLWithString:pic_url[@"bmiddle_pic"]];
        [self.bmiddle_pics addObject:URL2];
    }
}


@end
